/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.service.impl;

import cn.hutool.core.codec.Base64;
import com.alipay.api.domain.DeviceTradeInfoList;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.rcon.RCONClient;
import me.zhengjie.modules.rcon.RconClientDeep;
import me.zhengjie.modules.system.domain.PokerGoodInfo;
import me.zhengjie.modules.system.domain.dto.PokerGoodInfoQueryCriteria;
import me.zhengjie.modules.system.mapper.PokerGoodInfoMapper;
import me.zhengjie.modules.system.service.PokerGoodInfoService;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* @description 服务实现
* @author greazy
* @date 2025-04-07
**/
@Service
@RequiredArgsConstructor
public class RconServiceImpl  {

    public String sendCommond(String ip,String port,String passWord,String comType,String steamId,String goodId,Integer num){
        RconClientDeep client = new RconClientDeep(ip, Integer.parseInt(port), passWord);
        try {
            client.connect();
            System.out.println("Connected to RCON server");
            // 示例命令
            String commond = String.format("%s %s %s %d",comType,steamId,goodId,num);
            String encode = Base64.encode(commond.getBytes());
            String response = client.sendCommand(encode);
            byte[] decodedBytes = Base64.decode(response);
            System.out.println("Server response: " + new String(decodedBytes));
            return new String(decodedBytes);
        } catch (IOException e) {
            System.err.println("RCON error: " + e.getMessage());
        } finally {
            client.disconnect();
        }



        return null;
    }


}